CREATE TABLE [dbo].[TDDETA_FACT]
(
[CO_EMPR] [dbo].[TD_VC_002] NOT NULL,
[NU_ANNO] [dbo].[TD_IN_004_ANNO] NOT NULL CONSTRAINT [DF__TDDETA_FA__NU_AN__6A30C649] DEFAULT (datepart(year,getdate())),
[TI_AUXI_EMPR] [dbo].[TD_VC_001] NOT NULL,
[CO_AUXI_EMPR] [dbo].[TD_VC_020] NOT NULL,
[TI_DOCU] [dbo].[TD_VC_003] NOT NULL,
[NU_DOCU] [dbo].[TD_VC_020] NOT NULL,
[NU_CNTB_EMPR] [dbo].[TD_IN_001_CONT] NOT NULL,
[NU_SECU_FACT] [dbo].[TD_IN_001] NOT NULL,
[NU_FILA_DESC] [dbo].[TD_IN_001] NOT NULL,
[CO_SERV_FACT] [dbo].[TD_VC_003] NOT NULL,
[CO_MONE] [dbo].[TD_VC_003] NOT NULL,
[DE_SERV] [dbo].[TD_VC_100] NULL,
[CO_USUA_CREA] [dbo].[TD_VC_008_USUA] NOT NULL,
[FE_USUA_CREA] [dbo].[TD_DT_001_SIST] NOT NULL CONSTRAINT [DF__TDDETA_FA__FE_US__6D0D32F4] DEFAULT (getdate()),
[CO_USUA_MODI] [dbo].[TD_VC_008_USUA] NOT NULL,
[FE_USUA_MODI] [dbo].[TD_DT_001_SIST] NOT NULL CONSTRAINT [DF__TDDETA_FA__FE_US__6E01572D] DEFAULT (getdate())
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[TDDETA_FACT] ADD CONSTRAINT [CK__TDDETA_FA__NU_AN__6B24EA82] CHECK (([NU_ANNO]>=(0)))
GO
ALTER TABLE [dbo].[TDDETA_FACT] ADD CONSTRAINT [CK__TDDETA_FA__NU_CN__6C190EBB] CHECK (([NU_CNTB_EMPR]>=(1) AND [NU_CNTB_EMPR]<=(99)))
GO
ALTER TABLE [dbo].[TDDETA_FACT] ADD CONSTRAINT [XPKTDDETA_FACT] PRIMARY KEY CLUSTERED  ([CO_EMPR], [NU_ANNO], [TI_AUXI_EMPR], [CO_AUXI_EMPR], [TI_DOCU], [NU_DOCU], [NU_CNTB_EMPR], [NU_SECU_FACT], [NU_FILA_DESC]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[TDDETA_FACT] ADD CONSTRAINT [FK1_TCSERV_FACT_A_TDDETA_FACT] FOREIGN KEY ([CO_EMPR], [NU_ANNO], [CO_SERV_FACT]) REFERENCES [dbo].[TCSERV_FACT] ([CO_EMPR], [NU_ANNO], [CO_SERV_FACT])
GO
ALTER TABLE [dbo].[TDDETA_FACT] ADD CONSTRAINT [PK1_TDFACT_A_TDDETA_FACT] FOREIGN KEY ([CO_EMPR], [NU_ANNO], [TI_AUXI_EMPR], [CO_AUXI_EMPR], [TI_DOCU], [NU_DOCU], [NU_CNTB_EMPR], [NU_SECU_FACT]) REFERENCES [dbo].[TDFACT] ([CO_EMPR], [NU_ANNO], [TI_AUXI_EMPR], [CO_AUXI_EMPR], [TI_DOCU], [NU_DOCU], [NU_CNTB_EMPR], [NU_SECU_FACT])
GO
